<!--新增会员-->
<template>
  <section class="webview fixHeight">
    <el-scrollbar style="height:100%">
      <!--      经纪人-->
      
      
      <!--      开发商-->
      <el-form v-if="$route.query.type == 2" ref="form" :model="detail" label-width="100px" class="form">
        <el-form-item label="发布人">
          <el-input  v-model="detail.name" />
        </el-form-item>
		<el-form-item label="发布时间">
		  <el-input  v-model="detail.name" />
		</el-form-item>
		<el-form-item label="评论数">
		  <el-input  v-model="detail.name" />
		</el-form-item>
		<el-form-item label="点赞数">
		  <el-input  v-model="detail.name" />
		</el-form-item>
        <el-form-item >
          <el-input  type="textarea" :rows="4" placeholder="请输入..." v-model="detail.account" />
        </el-form-item>
        <el-form-item>
<!--          <el-button type="primary" @click="submit">提交</el-button>-->
          <el-button @click="cancel">返回</el-button>
        </el-form-item>
      </el-form>
      
    </el-scrollbar>
  </section>
</template>
<script>
  import { residentialList, houareaList, shopList, memberUpdate, memberAdd, memberDetail, developersAdd, developersDetail, developersUpdate, agentAdd, agentDetail, agentUpdate, housePropertytAdd, housePropertyDetail, housePropertyUpdate } from '@/api/api'
  export default {
    data() {
      return {
        fileListHead: [],
        fileListVideo: [],
        fileListLogo: [],
        fileListGsfc: [],
        fileListYyzz: [],
        fileListIntroduce: [],
        storeIdList: [],
        mainResidentialIdOptions: [],
        detail: {}
      }
    },
    created() {
      // 门店列表
      shopList({
        curPage: 1,
        pageSize: 9999,
        name: ''
      }).then(({ data }) => {
        this.storeIdList = data.records
      })
      // 小区列表 需要改一下
      residentialList({
        curPage: 1,
        pageSize: 6666,
        name: ''
      }).then(data => {
        this.mainResidentialIdOptions = data.data.records
      })
      if (this.$route.query.id) {
        // 房产公司
        if (this.$route.query.type == 3) {
          housePropertyDetail(this.$route.query.id).then(({ data }) => {
            this.detail = data
            if (this.detail.logo) {
              this.fileListLogo = [this.detail.logo]
            }
            this.detail.enterpriseResources.forEach((item, index) => {
              if (item.type == 0) {
                this.fileListGsfc.push(item.pictureUrl)
              }

              if (item.type == 1) {
                this.fileListYyzz.push(item.pictureUrl)
              }

              if (item.type == 2) {
                this.fileListIntroduce.push(item.pictureUrl)
              }
            })
          })
        }
        // 经纪人
        if (this.$route.query.type == 1) {
          agentDetail(this.$route.query.id).then(({ data }) => {
            this.detail = data
            if (this.detail.headPortrait) {
              this.fileListHead = [this.detail.headPortrait]
            }
          })
        }
        // 开发商
        if (this.$route.query.type == 2) {
          this.detail = JSON.parse(this.$route.query.id)
          this.fileListLogo = [this.detail.logo]
        }
        // 会员
        if (this.$route.query.type == 4) {
          memberDetail(this.$route.query.id).then(({ data }) => {
            this.detail = data
            if (this.detail.headPortrait) {
              this.fileListHead = [this.detail.headPortrait]
            }
          })
        }
      } else {
        if (this.$route.query.type == 1) {
          this.detail = {
            'aboutUs': '',
            'account': '',
            'email': '',
            'entryTime': '',
            'headPortrait': '',
            'id': '',
            'introduceUrl': '',
            'mainResidentialId': [
            ],
            'name': '',
            'phone': '',
            'storeId': '',
            'workYear': ''
          }
        }
        if (this.$route.query.type == 2) {
          this.detail = {
            'enterpriseType': '',
            'logo': '',
            'name': ''
          }
        }
        if (this.$route.query.type == 3) {
          this.detail = {
            'account': '',
            'briefIntroduction': '',
            'enterpriseResources': [
            ],
            'legalName': '',
            'logo': '',
            'mainBusiness': '',
            'name': '',
            'registeredPlace': ''
          }
        }
        if (this.$route.query.type == 4) {
          this.detail = {
            'account': '',
            'email': '',
            'headPortrait': '',
            'nickName': '',
            'phone': ''
          }
        }
      }
    },
    methods: {
      handleRemove(index) {
        this.fileList.splice(index, 1)
      },
      // 上传图片之前的验证
      handleUpload() {
      },
      // 上传成功之后的回调
      handleSuccess(res) {
        if (res.code === 200) {
          this.fileList.push(res.data)
          this.detail.imgLink = this.fileList[0]
        }
      },
      // 添加/编辑
      submit() {
        // 验证不通过则不提交
        // if (!this.vertify()) {
        //   return false
        // }
        if (this.$route.query.type == 1) {
          if (this.$route.query.id) {
            // 编辑
            agentUpdate(this.detail).then(data => {
              Is.tip('编辑成功', 2000, 'success')
              this.$router.back()
            })
          } else {
            // 新增
            agentAdd(this.detail).then(data => {
              Is.tip('添加成功', 2000, 'success')
              this.$router.back()
            })
          }
        }
        if (this.$route.query.type == 2) {
          if (this.$route.query.id) {
            // 编辑
            developersUpdate(this.detail).then(data => {
              Is.tip('编辑成功', 2000, 'success')
              this.$router.back()
            })
          } else {
            // 新增
            developersAdd(this.detail).then(data => {
              Is.tip('添加成功', 2000, 'success')
              this.$router.back()
            })
          }
        }
        if (this.$route.query.type == 3) {
          this.detail.enterpriseResources = []
          this.fileListGsfc.forEach(item => {
            this.detail.enterpriseResources.push({
              dataType: 0,
              pictureUrl: item,
              type: 0
            })
          })
          this.fileListYyzz.forEach(item => {
            this.detail.enterpriseResources.push({
              dataType: 0,
              pictureUrl: item,
              type: 1
            })
          })
          this.fileListIntroduce.forEach(item => {
            this.detail.enterpriseResources.push({
              dataType: 0,
              pictureUrl: item,
              type: 2
            })
          })
          if (this.$route.query.id) {
            // 编辑
            housePropertyUpdate(this.detail).then(data => {
              Is.tip('编辑成功', 2000, 'success')
              this.$router.back()
            })
          } else {
            // 新增
            housePropertytAdd(this.detail).then(data => {
              Is.tip('添加成功', 2000, 'success')
              this.$router.back()
            })
          }
        }
        if (this.$route.query.type == 4) {
          if (this.$route.query.id) {
            // 编辑
            memberUpdate(this.detail).then(data => {
              Is.tip('编辑成功', 2000, 'success')
              this.$router.back()
            })
          } else {
            // 新增
            memberAdd(this.detail).then(data => {
              Is.tip('添加成功', 2000, 'success')
              this.$router.back()
            })
          }
        }
      },
      // 返回
      cancel() {
        this.$router.back()
      },
      vertify() {
        if (Is.empty(this.detail.title)) {
          Is.tip('请输入标题')
          return false
        }
        if (Is.empty(this.detail.link)) {
          Is.tip('请输入链接')
          return false
        }
        if (Is.empty(this.detail.showType)) {
          Is.tip('请输入显示位置')
          return false
        }
        if (Is.empty(this.detail.sort)) {
          Is.tip('请输入排序')
          return false
        }
        if (Is.empty(this.fileList)) {
          Is.tip('请上传图片')
          return false
        }
        return true
      }
    }}
</script>
